package com.xiaofengstu.mcams.web.controller;


import com.xiaofengstu.mcams.annotation.ILog;
import com.xiaofengstu.mcams.dto.BasicResultDTO;
import com.xiaofengstu.mcams.enums.RespStatusEnum;
import com.xiaofengstu.mcams.web.entity.Workflow;
import com.xiaofengstu.mcams.web.service.WorkflowService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fengzeng
 * @since 2022-05-07
 */
@RestController
@RequestMapping("/web/workflow")
@RequiredArgsConstructor
public class WorkflowController {

  private final WorkflowService workflowService;


  @ILog("资产报废申请")
  @PostMapping("/discardApply")
  public BasicResultDTO<Integer> discardApply(@RequestBody Workflow workflow) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, workflowService.discardApply(workflow));
  }

  @ILog("资产维修申请")
  @PostMapping("/repairApply")
  public BasicResultDTO<Integer> repairApply(@RequestBody Workflow workflow) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, workflowService.repairApply(workflow));
  }

  @ILog("获取待审批列表")
  @GetMapping("/list")
  public BasicResultDTO<List<Workflow>> getList() {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, workflowService.defineList());
  }

  @ILog("审批通过")
  @PostMapping("/approve")
  public BasicResultDTO<Boolean> onApprove(@RequestBody Workflow workflow) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, workflowService.onApprove(workflow));
  }


  @ILog("审批拒绝")
  @PostMapping("/reject")
  public BasicResultDTO<Boolean> onReject(@RequestBody Workflow workflow) {
    return new BasicResultDTO<>(RespStatusEnum.SUCCESS, workflowService.onReject(workflow));
  }


}
